# Mr. Blackwell - the humble beginnings of a code profiler
# change the variable 'c' below to your language's comment character
# license: GPL3
# Michael S. Sanders

BEGIN {if (ARGC != 2) {q++; exit}; c="#"; x = y = z = 0}

{
    if ($0 ~ "^[[:blank:]]*" c) {
        x++
    } else if ($0 ~ "^[[:blank:]]*$") {
        y++
    } else {
        z++
    }
}

# ---------------------------------------------------------------------------

END {
    if (! q) {
        print "\n  Mr.Blackwell - script profiler v1.00\n"
        print "  source file:       " FILENAME
        print "  comment character: " c
        print "  lines total:       " NR
        print "  lines of comments: " x
        print "  lines of code:     " z
        print "  lines empty:       " y
        print "  code density:      " int(((z + x) / NR) * 100) "%\n"
    }
}

